<style lang="scss" scoped>
    .login-container {
        width: 100%;
        height: 100%;
        background: url("../../assets/bright.png");
        display: flex;
        align-items: center;
    }

    .login-page {
        -webkit-border-radius: 5px;
        border-radius: 5px;
        margin-left: auto;
        margin-right: auto;
        width: 350px;
        height: 290px;
        padding: 35px 35px 15px;
        background: #fff;
        border: 1px solid #eaeaea;
        box-shadow: 0 0 25px #cac6c6;
    }

    @media screen and (max-width: 450px) {
        .login-page {
            max-width: calc(90% - 40px);
            padding: 10px 20px 15px;
        }
    }

    label.el-checkbox.rememberme {
        margin: 0px 0px 15px;
        text-align: left;
    }
</style>
<template>
    <div class="login-container">
        <el-form :model="model" :rules="rules"
                 status-icon
                 ref="loginForm"
                 v-loading="loading"
                 label-position="left"
                 label-width="0px"
                 class="demo-ruleForm login-page">
            <h3 class="title">系统登录</h3>
            <el-form-item prop="username">
                <el-input type="text"
                          v-model="model.usernameOrEmailAddress"
                          auto-complete="off"
                          placeholder="用户名"
                ></el-input>
            </el-form-item>
            <el-form-item prop="password">
                <el-input type="password"
                          v-model="model.password"
                          auto-complete="off"
                          placeholder="密码"
                ></el-input>
            </el-form-item>
            <el-checkbox
                    v-model="model.remember"
                    class="rememberme"
            >记住登陆状态
            </el-checkbox>
            <el-form-item style="width:100%;">
                <el-button type="primary" style="width:100%;" @click="handleSubmit">登录</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>

<script>
    export default {
        name: "login",
        data() {
            return {
                loading: false,
                model: {
                    tenant: 1,
                    usernameOrEmailAddress: '',
                    password: '',
                    remember: false,
                },
                rules: {
                    usernameOrEmailAddress: [{required: true, message: '请输入账号', trigger: 'blur'}],
                    password: [{required: true, message: '请输入密码', trigger: 'blur'}]
                },
            }
        },
        created(){
            console.log('env:', process.env.VUE_APP_API_BASE_URL)
        },
        methods: {
            handleSubmit() {
                this.$refs.loginForm.validate((valid) => {
                    if (valid) {
                        this.loading = true
                        /*this.$apis.user.login(this.model).then(r => {
                            if (r.success) {
                                this.loading = false
                                localStorage.setItem(window.consts.strings.adminToken, r.result)
                                this.$msg.notify.success('登录成功', '登录成功，即将跳转');
                                setTimeout(() => {
                                    let q = this.$route.query
                                    let url = '/';
                                    if (q.returnUrl && q.returnUrl != '/login') {
                                        console.log('URL:', q.returnUrl)
                                        url+= q.returnUrl
                                    }
                                    window.location.href = url;
                                }, 1000)
                            } else {
                                this.loading = false;
                                this.$msg.alert.error(r.error.message, '');
                            }
                        })
                            .catch(e => {
                                console.log(e)
                                this.loading = false;
                            })*/
                    }
                })
            }
        }
    }
</script>

<style scoped>

</style>
